


#ifndef PF_HATCH_H
#define PF_HATCH_H

#include "pf_entity.h"
#include "pf_entitycontainer.h"
#include "lx_Export.h"

/**
 * Holds the data that defines a hatch entity.
 */
class LX_EXPORT PF_HatchAttribute {
public:
    /**
     * Default constructor. Leaves the data object uninitialized.
     */
    PF_HatchAttribute() {}

	/**
	 * @param solid true: solid fill, false: pattern.
	 * @param scale Pattern scale or spacing.
	 * @param pattern Pattern name.
	 */
    PF_HatchAttribute(bool solid,
	             double scale,
				 double angle,
                     const QString& pattern) {
		this->solid = solid;
		this->scale = scale;
		this->angle = angle;
		this->pattern = pattern;

		//std::cout << "PF_HatchData: " << pattern.toLatin1() << "\n";
	}

    friend std::ostream& operator << (std::ostream& os, const PF_HatchAttribute& td) {
        os << "(" << td.pattern.toLatin1().data() << ")";
        return os;
    }

public:
	bool solid;
	double scale;
	double angle;
        QString pattern;
};



/**
 * Class for a hatch entity.
 *

 */
class LX_EXPORT PF_Hatch : public PF_Container {
public:
    PF_Hatch(PF_Container* parent,
            const PF_HatchAttribute& d);
    virtual ~PF_Hatch() {}

    virtual PF_Entity* clone();

    /**	@return LX_Define::EntityHatch */
    virtual LX_Define::EntityType rtti() const {
        return LX_Define::EntityHatch;
    }
	
    /**
     * @return true: if this is a hatch with lines (hatch pattern),
     *         false: if this is filled with a solid color.
     */
    virtual bool isContainer() const {
		if (isSolid()) {
			return false;
		}
		else {
        	return true;
		}
    }

    /** @return Copy of data that defines the hatch. */
    PF_HatchAttribute getData() const {
        return data;
    }

	bool validate();
	
	int countLoops();

	/** @return true if this is a solid fill. false if it is a pattern hatch. */
	bool isSolid() const {
		return data.solid;
	}
	void setSolid(bool solid) {
		data.solid = solid;
	}

        QString getPattern() {
		return data.pattern;
	}
        void setPattern(const QString& pattern) {
		data.pattern = pattern;
	}
	
	double getScale() {
		return data.scale;
	}
	void setScale(double scale) {
		data.scale = scale;
	}
	
	double getAngle() {
		return data.angle;
	}
	void setAngle(double angle) {
		data.angle = angle;
	}

    virtual void calculateBorders();
    void update();
	void activateContour(bool on);
	
    virtual void draw(PF_Painter* painter, PF_GraphicView* view, 
		double patternOffset=0.0);

	virtual double getLength() {
		return -1.0;
	}
	
    virtual double getDistanceToPoint(const PF_Vector& coord,
                                      PF_Entity** entity = NULL,
                                      LX_Define::ResolveLevel level = LX_Define::ResolveNone,
									  double solidDist = LX_DOUBLEMAX);

    virtual void move(PF_Vector offset);
    virtual void rotate(PF_Vector center, double angle);
    virtual void scale(PF_Vector center, PF_Vector factor);
    virtual void mirror(PF_Vector axisPoint1, PF_Vector axisPoint2);
    virtual void stretch(PF_Vector firstCorner,
                         PF_Vector secondCorner,
                         PF_Vector offset);

    friend std::ostream& operator << (std::ostream& os, const PF_Hatch& p);

protected:
    PF_HatchAttribute data;
	PF_Container* hatch;
	bool updateRunning;
	bool needOptimization;
};

#endif
